export default instance => {
  // Add a response interceptor
  instance.interceptors.response.use((response) => {
    // console.log(response);
    if (response.status === 200 && response.data) {
      const { data } = response.data;
      if (data && data instanceof Object) {
        Object.keys(data)
          .forEach(key => {
            const val = data[key];
            const oldUrl = 'http://fastdfs.pesopop.com:9011';
            const newUrl = 'https://fastdfs.pesopop.com:19011';
            if (val && typeof val === 'string' && val.indexOf(oldUrl) > -1) {
              data[key] = val.replace(oldUrl, newUrl);
            }
          });
        // console.table(response.data.data);
      }
    }
    return response;
  }, error => Promise.reject(error));
};
